package cn.it.http.web;

import cn.it.http.entity.User;
import cn.it.http.service.Impl.UserService;
import cn.it.http.service.Impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Login2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String uname = req.getParameter("uname");
        String pwd = req.getParameter("pwd");
        User user = new User();
        user.setPwd(pwd);
        user.setUsername(uname);
        UserService userService = (UserService) new UserServiceImpl();
        User loginUser=userService.login2(user);
        if (loginUser!=null){
            req.getRequestDispatcher("index.jsp").forward(req,resp);
            return;
        }else {
            resp.sendRedirect("Login.jsp");
        }


    }
}
